package com.fuled.test.tool_config;

import com.fuled.test.tool_entity.ConstantPerformanceTool;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
import org.springframework.stereotype.Component;
import org.springframework.web.servlet.HandlerInterceptor;

import java.util.UUID;

/**
 * @author hcy
 * 拦截请求，并为请求request设置请求ID
 */
@Component
public class HeaderInterceptorPerformanceTool implements HandlerInterceptor {

    ///@Resource
    //private WFGIdGenerator wFGIdGenerator;

    @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
        request.setAttribute(ConstantPerformanceTool.REQUEST_ATTRIBUTE_NAME, System.currentTimeMillis());
        //request.setAttribute(ConstantPerformanceTool.REQUEST_ID, String.valueOf(wFGIdGenerator.next()));
        request.setAttribute(ConstantPerformanceTool.REQUEST_ID, String.valueOf(UUID.randomUUID()));
        return true;
    }
}